﻿/*******************************************************
 *
 * CLR版本：4.0.30319.42000
 * 说明：
 *
 * 历史记录：
 *     创建文件 Luomg 2021-08-23
 *
*******************************************************/
using System;
using System.Linq;
namespace EventBus {
    public static class GenericTypeExtensions {
        public static string GetGenericTypeName(this Type type) {
            var typeName = string.Empty;
            if(type.IsGenericType) {
                var genericTypes = string.Join(",",type.GetGenericArguments().Select(t => t.Name).ToArray());
                typeName = $"{type.Name.Remove(type.Name.IndexOf('`'))}<{genericTypes}>";
            } else {
                typeName = type.Name;
            }
            return typeName;
        }
        public static string GetGenericTypeName(this object @object) {
            return @object.GetType().GetGenericTypeName();
        }
    }
}